import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
// 内置管道
import { ParseIntPipe } from '@nestjs/common';

import { PipelineService } from './pipeline.service';
import { CreatePipelineDto } from './dto/create-pipeline.dto';
import { UpdatePipelineDto } from './dto/update-pipeline.dto';

// import { PipelinePipe } from './pipeline.pipe'

@Controller('pipeline')
export class PipelineController {
  constructor(private readonly pipelineService: PipelineService) {}

  @Post()
  // create(@Body(PipelinePipe) createPipelineDto: CreatePipelineDto) {      // 使用时，在装饰器中直接放入管道
  create(@Body() createPipelineDto: CreatePipelineDto) {      // 以上是自己做的管道验证，还可以使用nest自带的全局配置的，在main.ts中配置
    return this.pipelineService.create(createPipelineDto);
  }

  @Get()
  findAll() {
    return this.pipelineService.findAll();
  }

  @Get(':id')
  // findOne(@Param('id') id: string) {
  findOne(@Param('id', ParseIntPipe) id: number) {   // 用法
    //id是字符串类型，需要转换为数字类型
    return this.pipelineService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updatePipelineDto: UpdatePipelineDto) {
    return this.pipelineService.update(+id, updatePipelineDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.pipelineService.remove(+id);
  }
}
